package com.hirsi.core.util;

import cn.hutool.core.io.FileUtil;
import com.hirsi.ApplicationStarter;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class DbUtil {

    private static String DB_PATH = "/config/skyeysnow-netdisk.db";

    public static Connection connection;

    public static Statement statement;

    public static void init(){}

    static {
        if (System.getProperty("os.name").contains("Windows")) DB_PATH = "F:" + DB_PATH;
        if (!FileUtil.exist(DB_PATH)) FileUtil.writeFromStream(DbUtil.class.getResourceAsStream("/db/skyeysnow-netdisk.db"), DB_PATH);
        try {
            Class.forName("org.sqlite.JDBC");
            DbUtil.connection = DriverManager.getConnection(String.format("jdbc:sqlite:/%s", DB_PATH));
            DbUtil.statement = connection.createStatement();
            DbUtil.statement.setQueryTimeout(30);
        } catch (SQLException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        
    }
}
